/**
 * 
 */
package com.cari.oa.manage;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

/**
 * @author yanzihui
 *  2012-9-17
 */
public class GetRequest extends HttpServletRequestWrapper {
    private  static final String DEFAULT_CHARSET = "UTF-8";
	/**
	 * @param request
	 */
	public GetRequest(HttpServletRequest request) {
		super(request);
	}

	
	@Override
	public String getParameter(String name) {
		String value = super.getParameter(name);
		try {
			  if(value != null) {
				  value = new String(value.getBytes("ISO8859-1"), DEFAULT_CHARSET);
			  }
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return value;
	}

	
	@Override
	public String[] getParameterValues(String name) {
		 String[] values = super.getParameterValues(name);
		 if(values == null || values.length == 0) return null;
		 
		 String[] temps = Arrays.copyOf(values, values.length);
		 try {
			for (int i = 0; i < temps.length; i++) {
				String value = temps[i];
				temps[i] = new String(value.getBytes("ISO8859-1"), DEFAULT_CHARSET);
			}
		 } catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		 }
		 return temps;
	}
}
